<template>
  <div class="promotion-container">
    <div class="promotion-card">
      <div class="close-button">✕</div>
      <h1 class="title">分享有礼</h1>

      <!-- 步骤图标区域 -->
      <div class="steps-container">
        <div class="step">
          <div class="icon-circle">
            <i class="el-icon-user"></i>
          </div>
          <span class="step-text">创建优惠码</span>
        </div>
        <div class="step-arrow">or</div>
        <div class="step">
          <div class="icon-circle">
            <i class="el-icon-document-copy"></i>
          </div>
          <span class="step-text">复制链接</span>
        </div>
        <div class="step-arrow">or</div>
        <div class="step">
          <div class="icon-circle">
            <i class="el-icon-share"></i>
          </div>
          <span class="step-text">分享产品海报</span>
        </div>
        <div class="step-arrow">➜</div>
        <div class="step">
          <div class="icon-circle">
            <i class="el-icon-shopping-cart-full"></i>
          </div>
          <span class="step-text">新人下单</span>
        </div>
        <div class="step-arrow">➜</div>
        <div class="step">
          <div class="icon-circle">
            <i class="el-icon-present"></i>
          </div>
          <span class="step-text">获得权益</span>
        </div>
      </div>

      <!-- 优惠码输入区域 -->
      <div class="discount-section">
        <div class="discount-text">用推广链接享 <span style="color: red; font-weight: bold;">95</span> 折</div>
        <div class="input-group">
          <input type="text" placeholder="请输入推广链接 / 推广码" class="custom-input">
          <button class="confirm-button">确定</button>
        </div>
        <div class="notice-text">仅限新注册且未下过订单的用户使用。</div>
      </div>

      <!-- 推广链接区域 -->
      <div class="link-section">
        <div class="section-title">复制推广链接/保存二维码</div>
        <div class="link-input-group">
          <input type="text" :value="promotionLink" readonly class="link-input">
          <button class="copy-button" @click="copyLink">
            <i class="el-icon-document-copy"></i>
          </button>
        </div>
        <div class="qr-code">
          <img :src="qrCodeUrl" alt="QR Code">
          <span class="qr-text">保存推广二维码</span>
        </div>
      </div>

      <!-- 产品海报区域 -->
      <div class="poster-section">
        <div class="section-title">分享产品海报</div>
        <el-carousel trigger="click" height="500px" :autoplay="false">
          <el-carousel-item v-for="(poster, index) in posters" :key="index">
            <img :src="poster" alt="产品海报" class="poster-image">
          </el-carousel-item>
        </el-carousel>
        <div class="poster-tip">
          保存图片发送给好友，新用户好友下单即可获取佣金
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getPromotionLink, getQrCodeUrl } from '@/api/promotion'

export default {
  name: 'PromotionView',
  data() {
    return {
      promotionLink: 'https://nf.video/mzPll',
      qrCodeUrl: '',
      posters: [
        require('@/assets/promotion/poster1.png'),
        require('@/assets/promotion/poster2.png'),
        require('@/assets/promotion/poster3.png')
      ]
    }
  },
  methods: {
    copyLink() {
      navigator.clipboard.writeText(this.promotionLink);
      this.$message({
        message: '复制成功',
        type: 'success'
      });
    },
    getPromotionLink() {
      getPromotionLink().then(response => {
        this.promotionLink = response.data
      })
    },
    getQrCodeUrl() {
      getQrCodeUrl().then(response => {
        if (response.data && typeof response.data === 'string') {
          if (response.data.startsWith('data:image')) {
            this.qrCodeUrl = response.data;
          } else {
            this.qrCodeUrl = 'data:image/png;base64,' + response.data;
          }
        }
      }).catch(error => {
        console.error('获取二维码失败:', error);
        this.qrCodeUrl = require('@/assets/info/temp.png');
      })
    }
  },
  mounted() {
    this.getPromotionLink()
    this.getQrCodeUrl()
  }
}
</script>

<style scoped>
.promotion-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #F8F9FA;
  padding: 20px;
}

.promotion-card {
  background-color: #fff;
  border-radius: 16px;
  padding: 30px;
  width: 100%;
  max-width: 800px;
  position: relative;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
}

.close-button {
  position: absolute;
  right: 20px;
  top: 20px;
  font-size: 24px;
  cursor: pointer;
  color: #3F5D62;
  transition: all 0.3s ease;
}

.close-button:hover {
  transform: rotate(90deg);
}

.title {
  text-align: center;
  font-size: 2rem;
  margin-bottom: 30px;
  color: #3F5D62;
  font-weight: bold;
}

.steps-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #F8F9FA;
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 30px;
  border: 1px solid rgba(63, 93, 98, 0.1);
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.icon-circle {
  width: 40px;
  height: 40px;
  background-color: #fff;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #3F5D62;
  box-shadow: 0 2px 8px rgba(63, 93, 98, 0.1);
  transition: all 0.3s ease;
}

.icon-circle i {
  font-size: 20px;
}

.step:hover .icon-circle {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(63, 93, 98, 0.2);
}

.step-arrow {
  color: #3F5D62;
}

.step-text {
  font-size: 12px;
  color: #666;
}

.discount-section {
  margin-bottom: 30px;
}

.discount-text {
  font-size: 18px;
  color: #333;
  margin-bottom: 15px;
}

.input-group {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.custom-input {
  flex: 1;
  padding: 10px;
  border: 1px solid rgba(63, 93, 98, 0.2);
  border-radius: 8px;
  transition: all 0.3s ease;
}

.custom-input:focus {
  border-color: #3F5D62;
  outline: none;
  box-shadow: 0 0 0 2px rgba(63, 93, 98, 0.1);
}

.confirm-button {
  padding: 10px 20px;
  background-color: #3F5D62;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.confirm-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(63, 93, 98, 0.2);
}

.notice-text {
  font-size: 12px;
  color: #666;
}

.link-section {
  margin-bottom: 30px;
}

.link-input-group {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.link-input {
  flex: 1;
  padding: 10px;
  border: 1px solid rgba(63, 93, 98, 0.2);
  border-radius: 8px;
  background-color: #F8F9FA;
}

.copy-button {
  padding: 10px;
  background: #fff;
  border: 1px solid #3F5D62;
  border-radius: 8px;
  cursor: pointer;
  color: #3F5D62;
  transition: all 0.3s ease;
}

.copy-button:hover {
  background: #3F5D62;
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(63, 93, 98, 0.2);
}

.copy-button i {
  font-size: 16px;
}

.qr-code {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px;
  background: #F8F9FA;
  border-radius: 12px;
  border: 1px solid rgba(63, 93, 98, 0.1);
}

.qr-code img {
  width: 120px;
  height: 120px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(63, 93, 98, 0.1);
}

.poster-section {
  margin: 30px 0;
}

.el-carousel {
  border-radius: 12px;
  overflow: hidden;
}

.el-carousel__item {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #F8F9FA;
}

.poster-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  padding: 20px;
}

.poster-tip {
  font-size: 14px;
  color: #666;
  margin-top: 20px;
  text-align: center;
}

.section-title {
  font-size: 1.5rem;
  color: #3F5D62;
  margin-bottom: 20px;
  font-weight: 600;
}

/* 只保留箭头的自定义样式 */
:deep(.el-carousel__arrow) {
  background-color: rgba(63, 93, 98, 0.8);
}

:deep(.el-carousel__arrow:hover) {
  background-color: #3F5D62;
}

@media (max-width: 768px) {
  .steps-container {
    flex-wrap: wrap;
    gap: 15px;
  }
  
  .step {
    flex: 1 1 40%;
  }
  
  .step-arrow {
    display: none;
  }
}
</style>